package tests;

import game.Board;
import game.Piece;
import game.PieceBlue;

import java.awt.Point;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.junit.Test;

public class TestLevel1 {

	@Test
	public void test() {
		//COUNT PIECES = 8, 4H(1BLUE) + 4V 
		//int id, Point position, int size, boolean vertical
		int id=1;
		Map<Integer, Piece> pieces = new HashMap<Integer,Piece>();
		Map<Point, Integer> horizontalPoints = new HashMap<Point, Integer>();
		Map<Point, Integer> verticalPoints = new HashMap<Point, Integer>();
		horizontalPoints.put(new Point(0, 0), 2);
		horizontalPoints.put(new Point(4, 4), 2);
		horizontalPoints.put(new Point(2, 5), 3);
		
		verticalPoints.put(new Point(0, 1), 3);
		verticalPoints.put(new Point(0, 4), 2);
		verticalPoints.put(new Point(3, 1), 3);
		verticalPoints.put(new Point(5, 0), 3);

		PieceBlue pieceBlue = new PieceBlue(-1,new Point(1,2), 2,false);

		for(Entry<Point, Integer> entry : horizontalPoints.entrySet()){
			id++;
			pieces.put(id, new Piece(id, entry.getKey(), entry.getValue(), false));
		}
		for(Entry<Point, Integer> entry : verticalPoints.entrySet()){
			id++;
			pieces.put(id, new Piece(id, entry.getKey(), entry.getValue(), true));
		}
		
		Board board = new Board(6, 6, new Point(7,3), pieceBlue, getPieces(pieces));
		
		System.out.println("State 0 \n" + board);
		System.out.println("Move RIGHT");
		board = board.movePiece(pieces.get(2), new Point(3, 0));
		System.out.println("State 1 \n" + board);
		System.out.println("Move UP");
		board = board.movePiece(pieces.get(6), new Point(0, 0));
		System.out.println("State 2 \n" + board);
		System.out.println("Move UP");
		board = board.movePiece(pieces.get(5), new Point(0, 3));
		System.out.println("State 3 \n" + board);
		System.out.println("Move LEFT");
		board = board.movePiece(pieces.get(4), new Point(0, 5));
		System.out.println("State 4 \n" + board);
		System.out.println("Move LEFT");
		board = board.movePiece(pieces.get(3), new Point(1, 4));
		System.out.println("State 5 \n" + board);
		System.out.println("Move DOWN");
		board = board.movePiece(pieces.get(7), new Point(3, 3));
		System.out.println("State 6 \n" + board);
		System.out.println("Move DOWN");
		board = board.movePiece(pieces.get(8), new Point(5, 3));
		System.out.println("State 7 \n" + board);
		
		System.out.println("Move RIGHT BLUE");
		board = board.movePiece(pieceBlue, new Point(5, 2));
		System.out.println("State 7 \n" + board);
	}

	private List<Piece> getPieces(Map<Integer, Piece> entry){
		List<Piece> answer = new ArrayList<Piece>();
		for(Entry<Integer, Piece> piece : entry.entrySet()){
			answer.add(piece.getValue());
		}
		return answer;
	}
	
}
